package retrofix;

import retrofix.api.BiliService;
import retrofix.api.constants.ApiConstants;
import retrofix.entity.BiliDingVideo;
import okhttp3.OkHttpClient;
import retrofit2.Retrofit;
import retrofit2.adapter.rxjava.RxJavaCallAdapterFactory;
import retrofit2.converter.gson.GsonConverterFactory;
import rx.Scheduler;
import rx.Subscriber;
import rx.schedulers.Schedulers;

/**
 * Created by Administrator on 2017-03-14.
 */
public class RetrofixRx {

    public static void main(String arg[]) {

        Scheduler observeOn = Schedulers.computation(); // Or use mainThread() for Android.

        OkHttpClient.Builder httpClient = new OkHttpClient.Builder();

        Retrofit retrofit = new Retrofit.Builder()
                .baseUrl(ApiConstants.BILI_BASE_URL)
                .addConverterFactory(GsonConverterFactory.create())
                .addCallAdapterFactory(RxJavaCallAdapterFactory.create())
                .client(httpClient.build())
                .build();

        BiliService service = retrofit.create(BiliService.class);
        service.getDingVideosRx()
                .subscribeOn(Schedulers.io())
                .subscribe(new Subscriber<BiliDingVideo>() {
                    public void onCompleted() {

                        System.out.println("onCompleted");
                    }

                    public void onError(Throwable e) {

                        System.err.println("onError");
                    }

                    public void onNext(BiliDingVideo biliDingVideo) {

//                        System.out.println(biliDingVideo);
                    }
                });

        try {
            Thread.sleep(5000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}
